#!/usr/bin/perl
#vgdelete.cgi
require './lvm-lib.pl';
&ReadParse();
my $vgname = $in{'vg'};
my ($err_msg, $v, $vg, @vginfo);
@vginfo = get_vg_info();
if (!$vgname) {
	$err_msg = $text{'noselectvg'};
	goto ERROR_OUT;
}
my $found = 0;
foreach $v (@vginfo) {
	if ($v->{'vg'} eq $vgname) {
		$found = 1;
		$vg = $v;
		last;
	}
}

if (!$found) {
	$err_msg = $text{'err_vgnofound'};
	goto ERROR_OUT;
}
if ($vg->{'lvnum'} > 0 ) {
	$err_msg = $text{'err_existlv'};
	goto ERROR_OUT;
}
my $rc = remove_vg($vg);
if(!$rc){
	&redirect("index.cgi");
}
elsif($rc eq 1280){
	$err_msg = $text{'err_existlv'};
	goto ERROR_OUT;
}
else{
	$err_msg = $text{'err_delvg'};
	goto ERROR_OUT;
}
return;
ERROR_OUT:
&error_setup($text{'crt_err_title'});
&error($err_msg);
